﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ETRoboCon.TrackingSystem.SwitchBoxEmulater
{
    /// <summary>
    /// Interaction logic for SwitchBoxView.xaml
    /// </summary>
    public partial class SwitchBoxView : UserControl
    {
        private LinearGradientBrush leftSideDefaultBrush;
        private LinearGradientBrush rightSideDefaultBrus;

        public SwitchBoxView()
        {
            InitializeComponent();

            leftSideDefaultBrush = buttonLeftSide.Background.Clone() as LinearGradientBrush;
            rightSideDefaultBrus = buttonRightSide.Background.Clone() as LinearGradientBrush;
        }

        public String KindName
        {
            get
            {
                return labelKindName.Content.ToString();
            }
            set
            {
                labelKindName.Content = value;
            }
        }

        public string LeftSideButtonName
        {
            get
            {
                return buttonLeftSide.Content.ToString();
            }
            set
            {
                buttonLeftSide.Content = value;
            }
        }

        public string RightSideButtonName
        {
            get
            {
                return buttonRightSide.Content.ToString();
            }
            set
            {
                buttonRightSide.Content = value;
            }
        }

        public bool LeftSideButtonLED
        {
            set
            {
                SetButtonLED(buttonLeftSide, value);
            }
        }

        private void SetButtonLED(Button b, bool status)
        {
            if (status)
            {
                b.Background = new SolidColorBrush(Colors.Red);
            }
            else
            {
                b.Background = leftSideDefaultBrush;
            }
        }

        public bool RightSideButtonLED
        {
            set
            {
                SetButtonLED(buttonRightSide, value);
            }
        }

        private void buttonLeftSide_Click(object sender, RoutedEventArgs e)
        {
            if (OnLeftSideButtonPushed != null)
            {
                OnLeftSideButtonPushed(labelKindName.Content.ToString(), "Left", DateTime.Now);
            }
        }

        private void buttonRightSide_Click(object sender, RoutedEventArgs e)
        {
            if (OnRightSideButtonPushed != null)
            {
                OnRightSideButtonPushed(labelKindName.Content.ToString(), "Right", DateTime.Now);
            }
        }

        public delegate void ButtonPushHandler(string kindName, string buttonSide, DateTime timestamp);

        public event ButtonPushHandler OnLeftSideButtonPushed;
        public event ButtonPushHandler OnRightSideButtonPushed;

    }
}
